package config

import (
	"common/helper"
	"database/sql"
)

/*
客服配置表
*/

type CfgCustomerServiceItem struct {
	Id                  string `json:"id" db:"id"`
	Avatar              string `json:"avatar" db:"avatar"`
	CustomerServiceName string `json:"customer_service_name" db:"customer_service_name"`
	Title               string `json:"title" db:"title"`
	CustomerServiceType string `json:"customer_service_type" db:"customer_service_type"`
	OpenMethod          string `json:"open_method" db:"open_method"`
	CustomerServiceLink string `json:"customer_service_link" db:"customer_service_link"`
	State               string `json:"state" db:"state"`
}

type CsCustomerServiceCfg struct{}

var cfgCustomerServiceList []CfgCustomerServiceItem

func (that *CsCustomerServiceCfg) GetCfg() []CfgCustomerServiceItem {
	return cfgCustomerServiceList
}

func (that *CsCustomerServiceCfg) removeAllCfg() {
	cfgCustomerServiceList = []CfgCustomerServiceItem{}
}

func CustomerServiceCfgRemove() {
	cfgCustomerServiceList = []CfgCustomerServiceItem{}
}

func CustomerServiceCfgSetRow(rows *sql.Rows) {
	var tVal CfgCustomerServiceItem
	var err error
	err = rows.Scan(&tVal.Id, &tVal.Avatar, &tVal.CustomerServiceName, &tVal.Title, &tVal.CustomerServiceType, &tVal.OpenMethod, &tVal.CustomerServiceLink, &tVal.State)
	if err != nil {
		helper.InfoLog("CustomerServiceCfgSetRow,scan err")
		return
	}

	cfgCustomerServiceList = append(cfgCustomerServiceList, tVal)
}

func CfgCustomerService(state string) []CfgCustomerServiceItem {
	var custItem CfgCustomerServiceItem
	var custItems []CfgCustomerServiceItem
	for _, i := range cfgCustomerServiceList {
		if i.State == state {
			custItem = i
			custItems = append(custItems, custItem)
		}
	}
	return custItems
}
